<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="projects.task" %>
<%@ page import="projects.project" %>
<%@ page import="projects.issue" %>
<%@ page import="userInteraction.readUserInformation" %>
<%@ page import="java.util.ArrayList"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="taskInfo" class="projects.task"></jsp:useBean>
<jsp:setProperty property="*" name="taskInfo"/>
<jsp:useBean id="employees" class="projects.project"></jsp:useBean>
<jsp:setProperty property="*" name="employees"/>
<jsp:useBean id="issues" class="projects.issue"></jsp:useBean>
<jsp:setProperty property="*" name="issues"/>
<jsp:useBean id="user" class="userInteraction.readUserInformation"></jsp:useBean>
<jsp:setProperty property="*" name="user"/>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script language="JavaScript" type="text/javascript" src="../Tasks/ajax_search.js"></script>
<link rel="stylesheet" type="text/css" href="../General Info/css.css" />
<style type="text/css" media="screen">
	.suggest_link {
		background-color: #FFFFFF;
		padding: 2px 6px 2px 6px;
	}
	.suggest_link_over {
		background-color: #3366CC;
		padding: 2px 6px 2px 6px;
	}
	#search_suggest {
		position: absolute; 
		background-color: #FFFFFF; 
		text-align: left; 
		border: 1px solid #000000;			
	}		
</style>
<title>Task @ BPiM</title>
</head>

<%
if (request.getParameter("id") == null){
	response.sendRedirect("../General Info/dashboard.jsp");
}
else if (session.getAttribute("loggedIn") == null) {
	response.sendRedirect("../User/index.jsp");
	}
else{
task tsk = new task();
tsk.setTaskId(Integer.parseInt(request.getParameter("id")));
Integer taskId = Integer.parseInt(request.getParameter("id"));
ArrayList<String> info = tsk.queryTaskInfo();
Integer milestoneId = tsk.queryMilestoneId();
Integer projectId = tsk.queryProjectId();
%>

<body>

<jsp:include page="../General Info/header.jsp"/>


<%/* <!-- -----------------------------------------------> Submeniu <-------------------------------------------------- --> */%>
	<div class="submenu">
		<ul class="submenuBar">
			<%
			String taskLink = "../Tasks/task.jsp?id="+tsk.getTaskId();
			String projectLink = "../Projects/projectDashboard.jsp?id="+ projectId;
			String milestoneLink = "../Milestones/milestone.jsp?id="+ milestoneId;
			%>
			<li><a href=<% out.println(projectLink); %> class="submenuButton">Project</a></li>
			<li><a href=<% out.println(milestoneLink); %> class="submenuButton">Work Packages</a></li>
			<li><a href=<% out.println(taskLink); %> class="submenuButton">Task</a></li>
		</ul>
	</div>
	
<% /* ------------------------------------------------------------------------------------------------------------------------------- */ %>
	<div class="body">
		<div class="generalInfo">
		
		<div class="up">
			<div class = "projects">
			<div class = "projectsHeader">Task Information</div>
			<table style="float: left">
						<tr>
							<td class="labelName">Task Name:</td>
							<td class="labelValue"><%out.println(info.get(3)); %></td>
						</tr>
						<tr>
							<td class="labelName">Task Description:</td>
							<td class="labelValue" height="100%" width="100%"><%out.println(info.get(4)); %></td>
						</tr>
						<tr>
							<td class="labelName">Start date:</td>
							<td class="labelValue"><%out.println(info.get(1)); %></td>
						</tr>
						<tr>
							<td class="labelName">End date:</td>
							<td class="labelValue"><%out.println(info.get(2)); %></td>
						</tr>
						<tr>
							<td class="labelName">Task Priority:</td>
							<td class="labelValue"><%out.println(info.get(5)); %></td>
						</tr>
						<tr>
							<td class="labelName">Task Type:</td>
							<td class="labelValue"><%out.println(info.get(6)); %></td>
						</tr>
						<tr>
							<td class="labelName">Task Effort:</td>
							<td class="labelValue"><%out.println(info.get(7)); %></td>
						</tr>
						<tr>
							<td class="labelName">Task Status:</td>
							<td class="labelValue"><%out.println(info.get(8)); %></td>
						</tr>
						<tr>
							<td class="labelName">Task Resolution:</td>
							<td class="labelValue"><%out.println(info.get(9)); %></td>
						</tr>
						<tr>
							<td class="labelName">Assigned To:</td>
							<td class="labelValue"><%if(info.get(10).contentEquals("NULL NULL")){
								out.println("Not assigned!");
							}else{
								out.println(info.get(10));
							} %></td>
						</tr>
					</table>
			<%
			if(session.getAttribute("postback")=="true")
			{
				if (session.getAttribute("createTask")=="true") { %>
					<div class="successfulChange" id="successfulChange">New task added successfully!!</div>
					<%session.setAttribute("createTask", null);
					session.setAttribute("postback", null);
				}
				else if(session.getAttribute("createTask")=="false") {
					%><div class="notsuccessfulChange" id="notsuccessfulChange">Could not add task!!!</div>
					<%session.setAttribute("createTask", null);
					session.setAttribute("postback", null);
				}
			}
			else{
				%><div class="noChange" id="noChange"></div>	
			<%}%>
			</div>
	
			<div class="activity">
			<div class="projectsHeader">Actions</div>
			
			
	
		<div class="taskActions">
				<form name="changeStatusResolutionForm" onsubmit="" method="GET" action="../Tasks/changeStatusResolution.jsp">
					<% session.setAttribute("taskId", tsk.getTaskId()); %>
					</br>
					<table>
						<tr>
							<td>Change Task status and resolution:</td>
							<td><select name="taskStatus" id="taskStatus" onchange="status();">
							<option value="1">NEW</option>
							<option value="2">ASIGNED</option>
							<option value="3">RESOLVED</option>
							<option value="4">CLOSED</option>
							<option value="5">REOPENED</option>
							</select></td>
							<td><select name="taskResolution">
							<option value="5">NEW</option>
							<option value="1">FIXED</option>
							<option value="2">WOUN'T FIX</option>
							<option value="3">DUPLICATE</option>
							<option value="4">INVALID</option>
							<option value="7">CLOSED</option>
							</select></td>
						</tr>
						<tr><td></br></td></tr>
						<tr>
							<td>Assign to:</td>
							<td><input id="toEmployeeId" onkeyup="searchEmployees();" autocomplete="off"/>
								<div id="search_suggest">
								</div><input type="hidden" name="hEmployeeId" id="hEmployeeId" value="" />         
							</td>
						</tr>
						<tr>
							<td><input type="submit" class="inputButton" value="Change" /></td>
						</tr>
					</table>
					<% 
					if(session.getAttribute("postback")=="true")
					{
						if (session.getAttribute("changeStatusResolution")=="true") { %>
							<div class="successfulChange" id="successfulChange">Status and resolution changed successfully!!</div>
							<%session.setAttribute("changeStatusResolution", null);
							session.setAttribute("postback", null);
						}
						else if(session.getAttribute("changeStatusResolution")=="false") {
							%><div class="notsuccessfulChange" id="notsuccessfulChange">Could not change status and resolution!!!</div>
							<%session.setAttribute("changeStatusResolution", null);
							session.setAttribute("postback", null);
						}
					}
					else{
						%><div class="noChange" id="noChange"></div>	
					<%}%>
				</form>
			</div>
			
			</div>
		</div>
			
		<div class="down">
		<div class = "upcomingActivitiesb">
			<div class = "projectsHeader" style="text-align: left">Issues</div>
			
			<div class="newIssue">
				<form name="addNewIssueForm" onsubmit="" method="GET" action="../Tasks/addIssue.jsp">
					<fieldset class="fieldsetInfo">
						<legend>Add a new Issue</legend>
							<textarea rows="5" cols="120" id="newIssue" name="issueDescription"></textarea>
							<input type="submit" class="inputButton" value="Add Issue" />
							<input type="hidden" name="hTaskId" id="hTaskId" value=<% out.println("'"+taskId+"'"); %> />
					</fieldset>
					<% 
					if(session.getAttribute("postback")=="true")
					{
						if (session.getAttribute("createIssue")=="true") { %>
							<div class="successfulChange" id="successfulChange">New issue added successfully!!</div>
							<%session.setAttribute("createIssue", null);
							session.setAttribute("postback", null);
						}
						else if(session.getAttribute("createIssue")=="false") {
							%><div class="notsuccessfulChange" id="notsuccessfulChange">Could not add a new issue!!!</div>
							<%session.setAttribute("createIssue", null);
							session.setAttribute("postback", null);
						}
					}
					else{
						%><div class="noChange" id="noChange"></div>	
					<%}%>
				</form>
			</div>
			
			<div class="issues">				
			
			<div class="oldIssue">
				<%
				issue issue = new issue();
				issue.setTaskId(taskId);
				Hashtable<Integer, ArrayList<String>> issueInformation = issue.readIssue();
				Enumeration<Integer> keysEnum = issueInformation.keys();
				ArrayList<Integer> keys = new ArrayList<Integer>();
				while(keysEnum.hasMoreElements()){
					keys.add(keysEnum.nextElement());
				}
				int color = 0;
				for(Integer key : keys){
					color = color + 1;
					ArrayList<String> information = issueInformation.get(key);
					
					readUserInformation userInfo =new readUserInformation();
					if(color % 2 == 0){
				%>
				<fieldset class="even">
				<legend class="">Was added By: <% out.println(userInfo.readUserNameById(Integer.parseInt(information.get(1)))); %> at <% out.println(information.get(2)); %></legend>
				<% out.println(information.get(0)); %>
				</fieldset>
				<%}
					else{
						%>
						<fieldset class="odd">
				<legend class="">Was added By: <% out.println(userInfo.readUserNameById(Integer.parseInt(information.get(1)))); %> at <% out.println(information.get(2)); %></legend>
				<% out.println(information.get(0)); %>
				</fieldset>
						
					<%}
					}%>
			</div>	
				
		</div>
		</div>
		</div>				
			

			
		</div>
		<div class="push"></div>
		</div>
<jsp:include page="../General Info/footer.jsp"/>
</body>
<%} %>	
</html>